<?php

namespace App\Listener;

use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\AfterWorkerStart;
use Psr\Container\ContainerInterface;
use Yolo\Di\DI;
use Yolo\Service\ApplicationContainer;
use Yolo\Service\Subjects\AfterWorkerStartedSubject;
use Yolo\Utils\Console;

#[Listener]
class AfterWorkerStartListener implements ListenerInterface
{
    public function __construct(protected ContainerInterface $container)
    {
    }

    public function listen(): array
    {
        return [
            AfterWorkerStart::class,
        ];
    }

    public function process(object $event): void
    {
        $container = DI::use(ApplicationContainer::class);
        DI::use(AfterWorkerStartedSubject::class)->notify([
            'appScheme' => $container->getAppScheme(),
            'workerId' => $event->workerId,
        ]);

        Console::log("Service started.");
    }
}
